/*
 * @Author: szx
 * @Date: 2022-01-15 13:04:46
 * @LastEditTime: 2022-01-15 13:27:42
 * @Description: 
 * @FilePath: \leetcode\200-299\279\279.js
 */
/**
 * @param {number} n
 * @return {number}
 */
var numSquares = function (n) {
    const dp = new Array(n + 1).fill(n + 1);
    dp[0] = 0;
    for (let i = 1; i * i <= n; i++) {
        for (let j = i * i; j <= n; j++) {
            dp[j] = Math.min(dp[j], dp[j - i * i] + 1);
        }
    }
    return dp[n];
};
console.log(numSquares(12));